import moment from "moment";

const stateText = {0: "失效", 1: "正常", 2: "续费", 3: "终止"}
const detailText = {1: '套餐费', 2: '初装费', 3: "迁移费", 4: '增值费用', 5: "赠送时长"}
const remove = (data: any[], id: any) => {
  const list: any[] = []
  data.forEach((v: any) => {
    if (v !== id) {
      list.push(v)
    }
  })
  return list
}

const authority = (id: any, data: string | any[]) => {
  return data.includes(id)
}

const formatDate = (date: moment.MomentInput) => {
  return moment(date).format('YYYY-MM-DD')
}
const state = (text: any) => {
  return stateText[text]
}
const detail = (text: any) => {
  return detailText[text]
}
const checkData = (rule: any, value: any, callback: any) => {
  if (value) {
    if (/[\u4E00-\u9FA5]/g.test(value)) {
      callback(new Error('当前文本框不能包含汉字!'));
    } else {
      callback();
    }
  }
  callback();
}
const checkIdCard = (idCard: any) => {
  const id_card = idCard.toLowerCase();
  const test = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  const ids = id_card.split('');
  const key = {
    0: 1,
    1: 0,
    2: 'x',
    3: 9,
    4: 8,
    5: 7,
    6: 6,
    7: 5,
    8: 4,
    9: 3,
    10: 2,
  };
  let num = 0;
  // @ts-ignore
  test.map((v, i) => (num += v * ids[i]));
  // @ts-ignore
  if (idCard.length === 18) {
    // @ts-ignore
    return key[num % 11] == ids[17];
  } else {
    return false;
  }
};
export {
  remove,
  authority,
  formatDate,
  state,
  detail,
  checkIdCard,
  checkData
}
